import os


def makeDirx(dirx: str):
    items: list[str] = os.listdir(dirx)
    for item in items:
        if not item.endswith(".rs"):
            dirName = item + "x"
            fileName = os.path.join(dirName, "mod.rs")
            if not os.path.exists(dirName):
                os.mkdir(dirName)
            if not os.path.exists(fileName):
                os.open(fileName, os.O_CREAT, 0o666)
        elif not item == "mod.rs":
            ok = item.removesuffix(".rs")
            open(ok + "x.rs", "a")


def diffDir(dirx: str, diry: str):
    dirxList: list[str] = os.listdir(dirx)
    diryList: list[str] = os.listdir(diry)

    diryList = [item + "x" for item in diryList]
    dirxSet = set(dirxList)
    dirySet = set(diryList)

    print(dirxSet)
    print(dirySet)

    diffSet = dirxSet.difference(dirySet)
    print(diffSet)
    for _, e in enumerate(diffSet):
        os.renames(os.path.join(dirx, e), os.path.join("/home/debi/Desktop/aa/", e))


def walkDir(fromDir: str, toDir: str):
    items = os.listdir(fromDir)
    for item in items:
        fromNewDir = os.path.join(fromDir, item)

        if os.path.isdir(fromNewDir):
            toNewDir = os.path.join(toDir, item) + "x"
            if not os.path.exists(toNewDir):
                os.mkdir(toNewDir)
            mx = os.path.join(toNewDir, "mod.rs")
            if not os.path.exists(mx):
                open(mx, "a")
        else:
            item = item.removesuffix(".rs")
            toNewDir = os.path.join(toDir, "x_" + item)
            if not os.path.exists(toNewDir):
                os.mkdir(toNewDir)
            mx = os.path.join(toNewDir, "mod.rs")
            if not os.path.exists(mx):
                open(mx, "a")


if __name__ == '__main__':
    root = "/home/debi/.cache/JetBrains/IntelliJIdea2025.2/intellij-rust/stdlib-local-copy/1.91.0-662b30d5e92a309dad091df7b35b7dfd920da0a7/library/core/src"
    to = "/home/debi/IdeaProjects/LearnRust/Work/basic/src/corex"

    root = "/home/debi/.cache/JetBrains/IntelliJIdea2025.2/intellij-rust/stdlib-local-copy/1.91.0-662b30d5e92a309dad091df7b35b7dfd920da0a7/library/std/src"
    to = "/home/debi/IdeaProjects/LearnRust/Work/basic/src/stdx"

    walkDir(root + "/num", to + "/numx")
# diffDir(to, root)
